package com.xgkj.diyiketang.activity.data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xgkj.diyiketang.R;


/**
 * Created by windo on 16/8/3.
 */
public class SubjectAdapter extends BaseAdapter{
    private Context mContext;
    private int mPosition = -1;
    private String[] mList;

    /**
     * @param type 1 科目
     *             2 年级
     *             3 排序
     *             4 直播排序
     */
    public SubjectAdapter(Context context, int type) {
        mContext = context;
        if (type == 1) {
            mList = new String[]{"科目", "语文", "数学", "外语", "综合"};
        } else if (type == 2) {
            mList = new String[]{"年级", "一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "初一", "初二", "初三", "高一", "高二", "高三", "早教", "幼儿园", "综合"};
        } else if (type == 3) {
            mList = new String[]{"排序", "免费", "VIP", "从低到高", "最新上架", "人气排序"};
        } else if (type == 4) {
            mList = new String[]{"最新", "最热", "关注", "地区"};
        } else if (type == 5) {
            mList = new String[]{"全部", "最美教师", "今日课表", "每日精彩", "本周总结", "家长专区", "校长总结"};
        } else if (type == 6) {
            mList = new String[]{"全部直播", "同城直播"};
        }
    }

    public void setSelectPosition(int position) {
        mPosition = position;
    }

    @Override
    public int getCount() {
        if (mList != null) {
            return mList.length;
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (mList != null) {
            return mList[position];
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.choose_item, null);
            textView = (TextView) convertView.findViewById(R.id.text);
            convertView.setTag(textView);
        } else {
            textView = (TextView) convertView.getTag();
        }
        textView.setText(mList[position]);
        if (position == mPosition) {
            textView.setTextColor(mContext.getResources().getColor(R.color.shouye_tab_color_selected));
        } else {
            textView.setTextColor(mContext.getResources().getColor(R.color.detail_gray));
        }
        return convertView;
    }
}
